package com.sky.course.service;

import com.sky.course.entity.CmsMessageConfig;
import com.sky.course.entity.MessageForm;
import com.sky.course.exception.CustomizeException;
import com.sky.course.util.MessageUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class CmsService {
    @Value("${cms.appId}")
    private Integer appId;
    @Value("${cms.appKey}")
    private String appKey;
    @Value("${cms.templateId}")
    private Integer templateId;
    @Value("${cms.smsSign}")
    private String smsSign;
    public boolean sendMessage(MessageForm messageForm) {
        CmsMessageConfig cmsMessageConfig=new CmsMessageConfig();
        cmsMessageConfig.setAppId(appId);
        cmsMessageConfig.setAppKey(appKey);
        cmsMessageConfig.setTemplateId(templateId);
        cmsMessageConfig.setSmsSign(smsSign);
        try {
            MessageUtils.sendMessage(Boolean.FALSE,messageForm,cmsMessageConfig);
        } catch (CustomizeException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
